package com.basics.common.utils;


import org.apache.commons.collections4.CollectionUtils;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class ValidateUtil {
    private static Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

    public ValidateUtil() {
    }

    public static void beanValidate(Object obj) throws Exception {
        Map<String, String> validatedMsg = new HashMap();
        Set<ConstraintViolation<Object>> constraintViolations = validator.validate(obj, new Class[0]);
        Iterator var3 = constraintViolations.iterator();

        while(var3.hasNext()) {
            ConstraintViolation<Object> c = (ConstraintViolation)var3.next();
            validatedMsg.put(c.getPropertyPath().toString(), c.getMessage());
        }

        if (CollectionUtils.isNotEmpty(constraintViolations)) {
            throw new Exception(validatedMsg.toString());
        }
    }

    public static void main(String[] args) {
        BigDecimal moey = new BigDecimal(51);
        BigDecimal ms = new BigDecimal(2.5);
        System.out.println(moey.multiply(ms));
    }
}
